package com.dongline.test.join;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;

import java.io.IOException;

public class JoinMapper extends Mapper<LongWritable,Text, Text,OrderWritable> {


    OrderWritable orderWritable=new OrderWritable();

    Text text=new Text();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        FileSplit fileSplit=(FileSplit) context.getInputSplit();

        String line=value.toString();
        //如果是订单表
        if(fileSplit.getPath().getName().startsWith("order"))
        {

            String [] words=line.split(" ");
            orderWritable.setId(words[0]);
            orderWritable.setPid(words[1]);
            orderWritable.setUser(words[2]);

            orderWritable.setName("");
            orderWritable.setFlage(true);


            System.out.println("1121");
            context.write(new Text(words[1]),orderWritable);

            //如果是产品信息表
        }else{
            String [] words=line.split(" ");
            orderWritable.setId("");
            orderWritable.setPid(words[0]);
            orderWritable.setUser("");

            orderWritable.setName(words[1]);
            orderWritable.setFlage(false);


            text.set(words[0]);

            context.write(new Text(words[0]),orderWritable);

        }
    }
}
